#include<iostream>
#include<string>
#include<vector>
using namespace std;

//
//int main()
//{
//	int n;
//	vector<int> v;
//	cin >> n;
//	while (n--)
//	{
//		int m;
//		cin >> m;
//		v.push_back(m);
//	}
//	for (auto e : v)
//	{
//		cout << e << " ";
//	}
//	return 0;
//}


class Solution {
public:
	int maxArea(vector<int>& height) {
		int n = height.size(); int left = 0, right = n - 1;
		int max = 0, v = 0;;
		while (left < right)
		{
			v = (right - left) * min(height[left], height[right]);
			if (height[left] >= height[right]) right--;
			else left++;
			if (max < v) max = v;
		}
		return v;
	}
};


int main()
{
	vector<int> height = { 1,8,6,2,5,4,8,3,7 };
	Solution s;
	s.maxArea(height);
	return 0;
}